package org.abc.fund.entity.factorEntity;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import jakarta.persistence.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 因子树实体类
 */
@Entity
@Table(name = "factor_trees")
@Data
@EqualsAndHashCode(callSuper = false)
public class FactorTree {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    /**
     * 树名称
     */
    @Column(nullable = false, length = 200)
    private String treeName;

    /**
     * 树描述
     */
    @Column(columnDefinition = "TEXT")
    private String description;

    /**
     * 业务场景：FUND_SELECTION(选基), QUANT_RESEARCH(量化投研), SPECIAL_DATA(特色数据)
     */
    @Enumerated(EnumType.STRING)
    @Column(nullable = false)
    private BusinessScenario businessScenario;

    /**
     * 是否启用
     */
    @Column(nullable = false)
    private Boolean enabled = true;

    /**
     * 排序
     */
    @Column
    private Integer sortOrder = 0;

    /**
     * 创建时间
     */
    @CreationTimestamp
    @Column(nullable = false, updatable = false)
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    @UpdateTimestamp
    @Column(nullable = false)
    private LocalDateTime updateTime;

    /**
     * 创建人
     */
    @Column(length = 100)
    private String createdBy;

    /**
     * 更新人
     */
    @Column(length = 100)
    private String updatedBy;

    /**
     * 树节点关联
     */
    @OneToMany(mappedBy = "factorTree", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    @JsonManagedReference("tree-node")
    private List<FactorTreeNode> nodes;

    /**
     * 业务场景枚举
     */
    public enum BusinessScenario {
        FUND_SELECTION("选基所需因子"),
        QUANT_RESEARCH("量化投研所需因子"),
        SPECIAL_DATA("特色数据输出");

        private final String description;

        BusinessScenario(String description) {
            this.description = description;
        }

        public String getDescription() {
            return description;
        }
    }

    // ========== 补全getter/setter ==========
    public Long getId() { return id; }
    public void setId(Long id) { this.id = id; }
    public String getTreeName() { return treeName; }
    public void setTreeName(String treeName) { this.treeName = treeName; }
    public String getDescription() { return description; }
    public void setDescription(String description) { this.description = description; }
    public BusinessScenario getBusinessScenario() { return businessScenario; }
    public void setBusinessScenario(BusinessScenario businessScenario) { this.businessScenario = businessScenario; }
    public Boolean getEnabled() { return enabled; }
    public void setEnabled(Boolean enabled) { this.enabled = enabled; }
    public Integer getSortOrder() { return sortOrder; }
    public void setSortOrder(Integer sortOrder) { this.sortOrder = sortOrder; }
    public LocalDateTime getCreateTime() { return createTime; }
    public void setCreateTime(LocalDateTime createTime) { this.createTime = createTime; }
    public LocalDateTime getUpdateTime() { return updateTime; }
    public void setUpdateTime(LocalDateTime updateTime) { this.updateTime = updateTime; }
    public String getCreatedBy() { return createdBy; }
    public void setCreatedBy(String createdBy) { this.createdBy = createdBy; }
    public String getUpdatedBy() { return updatedBy; }
    public void setUpdatedBy(String updatedBy) { this.updatedBy = updatedBy; }
    public List<FactorTreeNode> getNodes() { return nodes; }
    public void setNodes(List<FactorTreeNode> nodes) { this.nodes = nodes; }
}